package Assignment2;

import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        // Create a hash set
        Student s1 = new Student("陆续","跑步","跳绳");
        Student s2 = new Student("陈云","跑步",null);
        Student s3 = new Student("吕不韦",null,"跳绳");
        Student s4 = new Student("李云龙","跑步",null);
        Student s5 = new Student("青云","跑步","跳绳");
        Set<Student> set = new HashSet<>();
        Set<String> set1 = new HashSet<>();   // 跑步
        Set<String> set2 = new HashSet<>();   // 跳绳
        Set<String> set4 = new HashSet<>();   // 参加比赛的同学
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);
        for (Student s: set) {
            if (s.getPor1() != null) {
                set1.add(s.getName());     // 把跑步
            }
            if (s.getPor2() != null) {
                set2.add(s.getName());
            }
        }
        set4.addAll(set2);
        set4.addAll(set1);
        System.out.println("参加运动会项目的同学："+set4);
        System.out.println("\n"+"参加校运会项目的同学人数："+set1.size());
        set4.removeAll(set2);
        set4.removeAll(set1);
        set4.removeAll(set2);
        set1.retainAll(set2);
        System.out.println("参加两个项目的同学："+set1);
        System.out.println("只参加了跳绳的同学："+set2);
    }
}
